<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<script>
  // rtmp://8.142.19.151:1935/1433248273132556288
  const url = 'http://8.142.19.151:6010/api/webrtc/play?streamPath=live/rtsp2'
  var path = new URL('http://8.142.19.151:6010/live/rtsp2')

  function assembleUrl4 (path) {
    const url = new URL(path)
    if (url.origin && url.origin !== 'null') {
      return `${url.origin}/api/webrtc/play?streamPath=${url.pathname}`
    } else {
      let pathname = url.pathname
      let host = ''
      let streamPath = ''
      let index = 0
      if (url.pathname.startsWith('//')) {
        pathname = url.pathname.substr(2)
        index = 2
      }

      index += pathname.indexOf('/')

      host = url.pathname.substring(0, index)
      streamPath = pathname.substring(index)

      if (pathname) {
        return `http:${host}/webrtc_api/webrtc/play?streamPath=${streamPath}`
      } else {
        console.log('url is Error for webRTC！')
      }
    }
  }

  function assembleUrl (path) {
    const url = new URL(path)
    if (url.origin && url.origin !== 'null') {
      return `${window.location.origin}/api/webrtc/play?streamPath=${url.pathname.substr(1)}`
    } else {
      let pathname = url.pathname
      let streamPath = ''
      let index = 0
      if (url.pathname.startsWith('//')) {
        pathname = url.pathname.substr(2)
      }

      index = pathname.indexOf('/')
      streamPath = pathname.substring(index + 1)

      if (pathname) {
        return `${window.location.origin}/webrtc_api/webrtc/play?streamPath=${streamPath}`
      } else {
        console.log('url is Error for webRTC！')
      }
    }
  }
  console.log('http://8.142.19.151:6010/live/rtsp2')
  console.log(assembleUrl('http://8.142.19.151:6010/live/rtsp2'))
</script>
</body>
</html>
